package jmu.edu.yjc.controller;

import io.swagger.annotations.ApiOperation;
import jmu.edu.yjc.annotation.SystemLog;
import jmu.edu.yjc.domain.ResponseResult;
import jmu.edu.yjc.domain.entity.User;
import jmu.edu.yjc.enums.AppHttpCodeEnum;
import jmu.edu.yjc.exception.SystemException;
import jmu.edu.yjc.service.AdminLoginService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class LoginController {
    @Resource
    private AdminLoginService adminLoginService;
    @PostMapping("/user/login")
    @SystemLog(businessName = "用户登录")
    @ApiOperation(value = "用户登录")
    public ResponseResult userLogin(@RequestBody User user){
        if(!StringUtils.hasText(user.getUserName())){
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return adminLoginService.userLogin(user);
    }
    @GetMapping("/getInfo")
    @ApiOperation(value = "获取用户权限信息")
    public ResponseResult getInfo(){
        return adminLoginService.getInfo();
    }
    @GetMapping("/getRouters")
    @ApiOperation(value = "获取用户可访问路由信息")
    public ResponseResult getRouters(){
        return adminLoginService.getRouters();
    }
    @PostMapping("/user/logout")
    public ResponseResult logout(){
        return adminLoginService.logout();
    }
}
